package com.test.jedis;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class JedisClusterDemo {

    private static String HOST = "10.200.120.211";
    public static void main(String[] args) {
        rwToNodes();
    }

    public static void rwToNodes() {
        // 初始化所有节点
        Set<HostAndPort> hostAndPorts = new HashSet<HostAndPort>();
        hostAndPorts.add(new HostAndPort(HOST, 7001));
        //得到集群连接对象
        JedisCluster cluster = new JedisCluster(hostAndPorts);
        String set = cluster.set("msg:001", "hello");
        String s = cluster.get("msg:001");
        System.out.println(s);
        try {
            //关闭资源
            cluster.close();
        }catch (IOException e) {
            System.out.println(e);
        }
    }
}
